package org.example.struct.array;

import com.alibaba.fastjson.JSON;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * @author liyishan
 * @date 2023/8/10 09:59
 * @apiNote
 */

public class Test00888FairCandySwap {
    public static void main(String[] args) {
        int[] aliceSizes = new int[]{2};
        int[] bobSizes = new int[]{1, 3};
        int[] result = test(aliceSizes, bobSizes);
        System.out.println(JSON.toJSON(result));
    }

    public static int[] test(int[] aliceSizes, int[] bobSizes) {
        int sumA = Arrays.stream(aliceSizes).sum();
        int sumB = Arrays.stream(bobSizes).sum();
        int delta = (sumA - sumB) / 2;
        Set<Integer> rec = new HashSet<Integer>();
        for (int num : aliceSizes) {
            rec.add(num);
        }
        int[] ans = new int[2];
        for (int y : bobSizes) {
            int x = y + delta;
            if (rec.contains(x)) {
                ans[0] = x;
                ans[1] = y;
                break;
            }
        }
        return ans;

    }
}
